package com.caipos.actor.common.actors;

import com.caipos.actor.common.msg.KbActorMsg;
import com.caipos.actor.common.msg.KbActorStopReason;

public interface KbActor {

    boolean process(KbActorMsg msg);

    KbActorRef getActorRef();

    default void init(KbActorCtx ctx) throws KbActorException {
    }

    default void destroy(KbActorStopReason stopReason, Throwable cause) throws KbActorException {
    }

    default InitFailureStrategy onInitFailure(int attempt, Throwable t) {
        return InitFailureStrategy.retryWithDelay(5000L * attempt);
    }

    default ProcessFailureStrategy onProcessFailure(KbActorMsg msg, Throwable t) {
        if (t instanceof Error) {
            return ProcessFailureStrategy.stop();
        } else {
            return ProcessFailureStrategy.resume();
        }
    }
}
